<?
$tableWriter = new CmsTableWriter("user", $db);
$formId = extractNumberWithKeyFromArray('formId', $_REQUEST, null);
$documentCode = extractNumberWithKeyFromArray('documentCode', $_REQUEST, null);
if ($documentCode) {
	$documentcontent = $cmsDocument->openDocument($documentCode);
}
else {
	$documentcontent = null;
}
?>
<div class="cms_browse_heading">
  <div class="cms_browse_heading_label">
    <h1>CMS Quick Link Category</h1>
  </div>
  <div class="cms_browse_addrecord"></div>
</div>
<div id="cms_browse_topdivider" class="cms_browse_divider"></div>
  <form class="cms_form" action="/cms/html/index.php" method="post" enctype="multipart/form-data" name="CMS Quick Link Category" id="CMS Quick Link Category">
    <input type="hidden" name="processFormData" value="YES" />
	<input type="hidden" name="fileNo" value="2">
	<input type="hidden" name="documenttypecode" value="docCMSLnkCat">
	<input type="hidden" name="formId" value="194">
	<input type="hidden" name="returnURL" value="<?= urlencode("/cms/html/index.php?fileNo=".FILE_BROWSE_QUICK_LINKS_CATEGORIES."&formid=194"); ?>">
	<?
	if (isset($documentCode) && $documentCode) {
	?>
	<input type="hidden" name="documentCode" value="<?= $documentCode; ?>">
	<?
	}
	?>
	<div class="cms_masteredit">
	  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="cms_masteraddedit_table" >
	    <tr>
		  <td height="1" width="160"><img src="/cms/images/spacer.gif" height="1" width="160" /></td>
		  <td height="1"><img src="/cms/images/spacer.gif" height="1" width="1" /></td>
		</tr>
		<tr id="cms_masteredit_194_10026" class="cms_masteraddedit_table"> 
		  <td id="cms_form_label_documentcode" class="cms_form_label" >Document Code:</td> 
		  <td class="cms_form_element" align="left">
		    <span id="cms_form_documentcode" class="cms_form_textlabel" name="documentcode" ><?= $documentCode; ?></span>
		  </td>
		</tr>
		<?
		//Check if admin - show select box of users
		//Else add hidden field for the current user
		if (permissionForMode($authInfo->uid, CMS_GROUP_ADMIN, $db)) {
		?>
		<tr id="cms_masteredit_194_11350" class="cms_masteraddedit_table"> 
		  <td id="cms_form_label_categorycode" class="cms_form_label" >User:</td> 
		  <td class="cms_form_element" align="left">
		    <select name="categorycode" id="cms_form_categorycode" class="cms_form_dropdown">
			  <option value="">All</option>
			  <?
			  $tableWriter->resetCustomIterator(" ORDER BY username");
			  while ($row = $tableWriter->nextItem()) {
				  echo "<option value='".$row->uid."'";
				  if (isset($documentcontent->categorycode) && $documentcontent->categorycode == $row->uid) {
					  echo " SELECTED";
				  }
				  echo ">".$row->username."</option>\n";
			  }
			  ?>
			</select>
		  </td>
		</tr>
		<?
		}
		else {
		?>
		<input type="hidden" name="categorycode" id="cms_form_categorycode" value="<?= $authInfo->uid; ?>">
		<?
		}
		?>
		<tr id="cms_masteredit_194_10001" class="cms_masteraddedit_table"> 
		  <td id="cms_form_label_datelogged" class="cms_form_label" >Last Updated:</td> 
		  <td class="cms_form_element" align="left">
		    <span id="cms_form_datelogged" class="cms_form_textlabel" name="datelogged" ><?= date("l d M Y H:i:s"); ?></span>
		  </td>
		</tr>
		<tr id="cms_masteredit_194_11219" class="cms_masteraddedit_table"> 
		  <td id="cms_form_label_title" class="cms_form_label" >Title:</td> 
		  <td class="cms_form_element" align="left">
		    <input type="text" name="title" value="<? if (isset($documentcontent->title)) echo magicClean($documentcontent->title); ?>" id="cms_form_title" class="cms_form_text"></input>
		  </td>
		</tr>
		<tr>
		  <td colspan="2" align="right" valign="middle">
		    <script language="javascript" type="text/javascript"> function selectAllElementsInSelect( select ) { for (i=0; i < select.options.length; i++){ select.options[i].selected = true; } return; } function doOnSubmitForElementsOnForm( formName ){ f = document.getElementById( formName ); if (f != null){ for (j = 0; j < f.length; j++ ){ e = f[j]; if (e.onsubmit){ e.onsubmit(); } } } return; } </script>
			<a id="cms_form_submit_194" class="cms_form_submit" href="javascript:doOnSubmitForElementsOnForm('CMS Quick Link Category');document.forms['CMS Quick Link Category'].submit();" ><img src="/cms/images/button_go.gif" /></a>
		  </td>
		</tr>
	  </table>
	</form>
  </div>
